package com.parsechina.hpush.broker.parser;


import io.netty.handler.codec.mqtt.*;

/**
 * @author linfeng
 * @since 2016/11/22
 */
public class PubRecMessage extends PushMessage {

    private static final long serialVersionUID = 2803533244551179610L;

    private int messageId;

    public PubRecMessage(MqttMessage msg) {
        super(msg);
        MqttMessageIdVariableHeader variableHeader = (MqttMessageIdVariableHeader) getMsg().variableHeader();
        messageId = variableHeader.messageId();
    }

    public PubRecMessage() {
    }

    public int getMessageId() {
        return messageId;
    }

    public void setMessageId(int messageId) {
        this.messageId = messageId;
    }

    public MqttMessage build() {
        MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBREC, false, MqttQoS.AT_MOST_ONCE, false, 0);
        MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);
        return new MqttMessage(fixedHeader, variableHeader);
    }

}
